	use "$data/secondary/final_data.dta", clear
	
		
	cap program drop CDF_boys
	program define CDF_boys
	
			*1: dependent variable
			*2: title of x-axis
			*3: xscale
			*4: xlabel
			*5: far left tail of distribution of DMQ index not shown
			*6: title of graph
			
			cap drop Cntrl_Boys Treat_Boys
			
			cumul `1' if male== 1 & ITT == 0, gen(Cntrl_Boys) equal
			cumul `1' if male== 1 & ITT == 1, gen(Treat_Boys) equal

			`5'
			
			twoway 	(line Cntrl_Boys `1' if ITT == 0 & male == 1, sort lcolor(ebblue) 	 lwidth(med) lpattern(dash)  connect(stairstep)) ///	
					(line Treat_Boys `1' if ITT == 1 & male == 1, sort lcolor(eltblue) 	 lwidth(med) lpattern(solid)  connect(stairstep)) ///				
					, ylabel(, nogrid) graphregion(fcolor(white)) xtitle("`2'") ytitle("Cumulative Distribution") /// 
					title("`6'", size(medium) ring(0) position(12)) legend(order(1 "Control Boys" 2 "Treatment Boys") region(lstyle(none))) ///
					yscale(range(0 1)) ylabel(0(.2)1) ///
					xscale(range(`3')) xlabel(`4')
					
	end			
	
	cap program drop CDF_girls
	program define CDF_girls
	
			*1: dependent variable
			*2: title of x-axis
			*3: xscale
			*4: xlabel
			*5: far left tail of distribution of DMQ index not shown
			*6: title of graph
			
			cap drop Cntrl_Girls Treat_Girls
			
			cumul `1' if male== 0 & ITT == 0, gen(Cntrl_Girls) equal
			cumul `1' if male== 0 & ITT == 1, gen(Treat_Girls) equal
			
			`5'
			
			twoway 	(line Cntrl_Girls `1' if ITT == 0 & male == 0, sort lcolor(pink*1.5) 	 lwidth(med) lpattern(dash)  connect(stairstep)) ///	
					(line Treat_Girls `1' if ITT == 1 & male == 0, sort  lcolor(pink*0.5) 	 lwidth(med) lpattern(solid)  connect(stairstep)) ///				
					, ylabel(, nogrid) graphregion(fcolor(white)) xtitle("`2'") ytitle("Cumulative Distribution") /// 
					title("`6'", size(medium) ring(0) position(12)) legend(order(1 "Control Girls" 2 "Treatment Girls") region(lstyle(none))) /// 
					yscale(range(0 1)) ylabel(0(.2)1) ///
					xscale(range(`3')) xlabel(`4')
			
	end				
	
	******************************************************
	***						FIGURE 1   		           ***
	******************************************************
	
	CDF_boys  daycare_attendance "Number of Years of Daycare Attendance" "0 4" "0(1)4"
	CDF_girls daycare_attendance "Number of Years of Daycare Attendance" "0 4" "0(1)4"
	
	******************************************************
	***						FIGURE 2   		           ***
	******************************************************
	
	preserve
	
		keep if perceptual_reasoning < . &  processing_speed < . & verbal_comprehension < . &  working_memory < .
		
		xtile half = st_DMQ, nquantiles(2)
		
		twoway (kdensity perceptual_reasoning if half == 1, lcolor(black)) (kdensity perceptual_reasoning if half == 2, lcolor(red) lpattern(dash)) ///
		, ylabel(, nogrid) graphregion(fcolor(white)) xtitle("Perceptual Reasoning")  ytitle("Density Perceptual Reasoning") ///  
		title("", size(medium) ring(0) position(12)) legend(order(1 "Bottom Half DMQ Index" 2 "Top Half DMQ Index") region(lstyle(none))) //

		twoway (kdensity processing_speed if half == 1, lcolor(black)) (kdensity processing_speed if half == 2, lcolor(red) lpattern(dash)) ///
		, ylabel(, nogrid) graphregion(fcolor(white)) xtitle("Processing Speed") ytitle("Density Processing Speed") /// 
		title("", size(medium) ring(0) position(12)) legend(order(1 "Bottom Half DMQ Index" 2 "Top Half DMQ Index") region(lstyle(none))) //
						
		twoway (kdensity verbal_comprehension if half == 1, lcolor(black)) (kdensity verbal_comprehension if half == 2, lcolor(red) lpattern(dash)) ///
		, ylabel(, nogrid) graphregion(fcolor(white)) xtitle("Verbal Comprehension")  ytitle("Density Verbal Comprehension") /// 
		title("", size(medium) ring(0) position(12)) legend(order(1 "Bottom Half DMQ Index" 2 "Top Half DMQ Index") region(lstyle(none))) //

		twoway (kdensity working_memory if half == 1, lcolor(black)) (kdensity working_memory if half == 2, lcolor(red) lpattern(dash)) ///
		, ylabel(, nogrid) graphregion(fcolor(white)) xtitle("Working Memory")  ytitle("Density Working Memory") /// 
		title("", size(medium) ring(0) position(12)) legend(order(1 "Bottom Half DMQ Index" 2 "Top Half DMQ Index") region(lstyle(none))) //
	
	restore
	
	******************************************************
	***						FIGURE 3   		           ***
	******************************************************
	
	CDF_boys  st_DMQ "Decision-Making Quality Index" "-4 2" "-4(2)2" "keep if st_DMQ >= -4"
	CDF_girls st_DMQ "Decision-Making Quality Index" "-4 2" "-4(2)2" "keep if st_DMQ >= -4"

	CDF_boys  st_risk_aversion "Risk Tolerance" "-3 1" "-3(1)1"
	CDF_girls st_risk_aversion "Risk Tolerance" "-3 1" "-3(1)1"
	
	CDF_boys  aversion_DI "Difference between # Allocated to Participant and # Allocated to Other Child"  "-2.5 0" "-2.5(.5)0" "" "Aversion to Disadvantageous Inequality"
	CDF_girls aversion_DI "Difference between # Allocated to Participant and # Allocated to Other Child"  "-2.5 0" "-2.5(.5)0" ""  "Aversion to Disadvantageous Inequality"

	CDF_boys  pref_AI "Difference between # Allocated to Participant and # Allocated to Other Child" "0 2" "0(.5)2" "" "Preference for Advantageous Inequality"
	CDF_girls pref_AI "Difference between # Allocated to Participant and # Allocated to Other Child" "0 2" "0(.5)2" "" "Preference for Advantageous Inequality"

	CDF_boys  waiting_time "Waiting Time in Marshmallow Task (in minutes)" "0 25" "0(5)25"
	CDF_girls waiting_time "Waiting Time in Marshmallow Task (in minutes)" "0 25" "0(5)25"
	
	******************************************************
	***						TABLE 1	          	 	   ***
	******************************************************
	
	xtset cluster
	
	
	foreach depvar in DMQ risk_aversion aversion_DI pref_AI waiting_time  {
		
		xtreg st_`depvar' male_ITT female_ITT male, r fe
		
	}
	
	qui tab cluster, gen(cluster_)

	rwolf DMQ risk_aversion aversion_DI pref_AI waiting_time, indepvar(female_ITT male_ITT) controls(cluster_* male) seed(70086298) reps(1000) 	
	
	******************************************************
	***						FIGURE 4   		           ***
	******************************************************
	
	use "$data/data_JPE_2019_deidentified.dta", clear
		
		
	replace inequalitylucky = inequalitylucky * 10
	replace inequalitymerit = inequalitymerit * 10
	
	gen male = female == 0
	
	
	cap program drop Cappelen_boys
	program define Cappelen_boys
	
			*1: dependent variable
			*2: title of x-axis
			*3: xscale
			*4: xlabel
			*5: far left tail of distribution of DMQ index not shown
			
			cap drop Cntrl_Boys Treat_Boys
			
			cumul `1' if male== 1 & any_PK == 0 & any_PA == 0, gen(Cntrl_Boys) equal
			cumul `1' if male== 1 & any_PK == 1 & any_PA == 0, gen(Treat_Boys) equal

			twoway 	(line Cntrl_Boys `1' if any_PK == 0 & any_PA == 0 & male == 1, sort lcolor(ebblue) 	 lwidth(med) lpattern(dash)  connect(stairstep)) ///	
					(line Treat_Boys `1' if any_PK == 1 & any_PA == 0 & male == 1, sort lcolor(eltblue) 	 lwidth(med) lpattern(solid)  connect(stairstep)) ///				
					, ylabel(, nogrid) graphregion(fcolor(white)) xtitle("`2'") ytitle("Cumulative Distribution") /// 
					title("", size(medium) ring(0) position(12)) legend(order(1 "Control Boys" 2 "Treatment Boys")) ///
					yscale(range(0 1)) ylabel(0(.2)1) ///
					xscale(range(`3')) xlabel(`4')
					
	end			
	
	cap program drop Cappelen_girls
	program define Cappelen_girls
	
			*1: dependent variable
			*2: title of x-axis
			*3: xscale
			*4: xlabel
			
			cap drop Cntrl_Girls Treat_Girls
			
			cumul `1' if male== 0 & any_PK == 0 & any_PA == 0, gen(Cntrl_Girls) equal
			cumul `1' if male== 0 & any_PK == 1 & any_PA == 0, gen(Treat_Girls) equal
			
			twoway 	(line Cntrl_Girls `1' if any_PK == 0 & any_PA == 0 & male == 0, sort lcolor(pink*1.5) 	 lwidth(med) lpattern(dash)  connect(stairstep)) ///	
					(line Treat_Girls `1' if any_PK == 1 & any_PA == 0 & male == 0, sort  lcolor(pink*0.5) 	 lwidth(med) lpattern(solid)  connect(stairstep)) ///				
					, ylabel(, nogrid) graphregion(fcolor(white)) xtitle("`2'") ytitle("Cumulative Distribution") /// 
					title("", size(medium) ring(0) position(12)) legend(order(1 "Control Girls" 2 "Treatment Girls")) /// 
					yscale(range(0 1)) ylabel(0(.2)1) ///
					xscale(range(`3')) xlabel(`4')
			
	end				
	
	******************************************************
	******************************************************
		
	Cappelen_boys  inequalitylucky "Difference in Number Allocated to Each Child" "0 10" "0(1)10" 
	Cappelen_girls inequalitylucky "Difference in Number Allocated to Each Child" "0 10" "0(1)10"
